<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no"/>
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <!--[if lt IE 9]>
    <script type="text/javascript" src="lib/html5shiv.js"></script>
    <script type="text/javascript" src="lib/respond.min.js"></script>
    <![endif]-->
    <link rel="stylesheet" type="text/css" href="static/h-ui/css/H-ui.min.css"/>
    <link rel="stylesheet" type="text/css" href="static/h-ui.admin/css/H-ui.admin.css"/>
    <link rel="stylesheet" type="text/css" href="lib/Hui-iconfont/1.0.8/iconfont.css"/>
    <link rel="stylesheet" type="text/css" href="lib/layui-v2.5.6/layui/css/layui.css"/>
    <link rel="stylesheet" type="text/css" href="static/h-ui.admin/skin/default/skin.css" id="skin"/>
    <link rel="stylesheet" type="text/css" href="static/h-ui.admin/css/style.css"/>
    <!--[if IE 6]>
    <script type="text/javascript" src="lib/DD_belatedPNG_0.0.8a-min.js"></script>
    <script>DD_belatedPNG.fix('*');</script>
    <![endif]-->
    <title>品牌管理</title>
</head>
<body>
<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 产品管理 <span
        class="c-gray en">&gt;</span> 品牌管理 <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px"
                                              href="javascript:location.replace(location.href);" title="刷新"><i
        class="Hui-iconfont">&#xe68f;</i></a></nav>
<div class="page-container">
    <div class="mt-20">
        <table id="productList" lay-filter="productFilter"></table>
    </div>
</div>
<!--_footer 作为公共模版分离出去-->
<script type="text/javascript" src="lib/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript" src="lib/layer/2.4/layer.js"></script>
<script type="text/javascript" src="static/h-ui/js/H-ui.min.js"></script>
<script type="text/javascript" src="static/h-ui.admin/js/H-ui.admin.js"></script> <!--/_footer 作为公共模版分离出去-->

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="lib/My97DatePicker/4.8/WdatePicker.js"></script>
<script type="text/javascript" src="lib/datatables/1.10.0/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="lib/laypage/1.2/laypage.js"></script>
<script type="text/javascript" src="lib/layui-v2.5.6/layui/layui.js"></script>
<script type="text/html" id="protductTool">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm" lay-event="add">添加</button>
        <button class="layui-btn layui-btn-sm" lay-event="delete">删除</button>
    </div>
</script>
<script type="text/javascript">
    var layer;
    var productBrandIds = [];
    var tableId;
    $(document).ready(function () {
        layui.use(['table', 'layer'], function () {
            var table = layui.table;
            layer = layui.layer;
            //第一个实例
            tableId = table.render({
                elem: '#productList'
                , url: '/Olala/goodsBrand/listAll' //数据接口
                , method: "post"
                , toolbar: "#protductTool"
                , response: {
                    statusCode: 20 //规定成功的状态码，默认：0
                }
                , page: true //开启分页
                , cols: [
                    [ //表头
                        {type: "checkbox", width: "5%"}
                        , {field: 'brandId', title: 'ID', width: "5%", sort: true}
                        , {field: 'brandLogo', title: '品牌LOGO', width: "20%"}
                        ,
                        {
                            field: 'brandName', title: '品牌名字', width: "20%", sort: true,
                            templet: function (data) {
                                return "<a href='javaScript:void(0)' onclick='productBrand(" + data.brandId + ")'>" + data.brandName + "</a>";
                            }
                        }
                        , {field: 'brandDesc', title: '描述', width: "30%"}
                        ,
                        {
                            field: 'isShow', title: '是否启用', width: "10%",
                            templet: function (data) {
                                return data.isShow === 1 ? "是" : "否";
                            }
                        }
                        ,
                        {
                            title: "操作", width: "10%",
                            templet: function (data) {
                                return "<button class=\"layui-btn layui-btn-sm\" lay-event=\"update\" onclick='updateProduct(" + data.brandId + ")'>编辑</button>"
                            }
                        }
                    ]
                ]
            });


            table.on('checkbox(productFilter)', function (obj) {
                if (obj.checked) {
                    productBrandIds[obj.data.brandId] = obj.data.brandId;
                } else {
                    productBrandIds.splice(obj.data.brandId, 1);
                }
            });

            table.on('toolbar(productFilter)', function (obj) {
                switch (obj.event) {
                    case 'add':
                        addProduct();
                        break;
                    case 'delete':
                        deleteProduct();
                        break;
                }
            });
        });


    });

    function updateProduct(id) {
        localStorage.setItem("productBrandId", id)
        var index = layer.open({
            type: 2,
            title: "添加",
            content: "product-brand-update.html",
            end: function () {
                localStorage.removeItem("productBrandId");
                tableId.reload();
            }
        });
        layer.full(index);
    }

    function productBrand(id) {
        localStorage.setItem("productBrandId", id)
        var index = layer.open({
            type: 2,
            title: "详情",
            content: "product-brand-info.html",
            end: function () {
                localStorage.removeItem("productBrandId");
                tableId.reload();
            }
        });
        layer.full(index);
    }

    function addProduct() {
        var index = layer.open({
            type: 2,
            title: "添加",
            content: "product-brand-add.html",
            end: function () {
                tableId.reload();
            }
        });
        layer.full(index);
    }

    function deleteProduct() {
        var index = layer.confirm('确认删除？', {
            btn: ['确认', '取消'], //按钮
            end: function () {
                tableId.reload();
            }
        }, function () {
            var ids = [];
            for (var i = 0; i < productBrandIds.length; i++) {
                if (productBrandIds[i]) {
                    ids.push(productBrandIds[i]);
                }
            }
            $.ajax({
                url: "/Olala/goodsBrand/delByIds",
                data: {
                    ids: ids
                },
                traditional: true,
                dataType: "json",
                type: "post",
                success: function (result) {
                    layer.msg(result.msg);
                    layer.close(index);
                }
            });
        }, function () {
            layer.close(index);
        });
    }
</script>
</body>
</html>